﻿using System;
using System.Windows.Forms;
using System.Drawing;


namespace EyeTracker_IA_Project
{
    /// <summary>
    /// Apre una finestra di dialogo che prende nome e cognome
    /// </summary>
    static class InputBox
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="title">il titolo</param>
        /// <param name="promptText">il messaggio che si visualizzera' </param>
        /// <param name="value">una stringa su cui verra' inserito il valore di ritorno</param>
        /// <returns></returns>
        public static DialogResult OpenInputBox(string title, string promptText, ref string value)
        {
            Form form = new Form();
            Label label = new Label();
            TextBox textBoxName = new TextBox();
            TextBox textBoxSurname = new TextBox();
            Button buttonOk = new Button();
            Button buttonCancel = new Button();


            form.Text = title;
            label.Text = promptText;
            textBoxName.Text = value;
            textBoxSurname.Text = value;

            buttonOk.Text = "OK";
            buttonCancel.Text = "Cancel";
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;

            label.SetBounds(9, 20, 372, 13);
            textBoxName.SetBounds(12, 36, 372, 20);
            textBoxSurname.SetBounds(12, 60, 372, 20);
            buttonOk.SetBounds(228, 96, 75, 23);
            buttonCancel.SetBounds(309, 96, 75, 23);

            label.AutoSize = true;
            textBoxName.Anchor = textBoxName.Anchor | AnchorStyles.Right;
            textBoxSurname.Anchor = textBoxSurname.Anchor | AnchorStyles.Right;
            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            form.ClientSize = new Size(396, 127);
            form.Controls.AddRange(new Control[] { label, textBoxName, textBoxSurname, buttonOk, buttonCancel });
            form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;

            DialogResult dialogResult = form.ShowDialog();
            value = textBoxName.Text.Trim() + textBoxSurname.Text.Trim();
            
            return dialogResult;
        }
    }
}